// list::unique
#include <iostream>
#include <cmath>
#include <list>

using namespace std;

// a binary predicate implemented as a function:
bool same_integral_part(double first, double second)
{
    return (int(first) == int(second));
}

// a binary predicate implemented as a class:
struct is_near
{
    bool operator()(double first, double second)
    {
        return (fabs(first - second) < 5.0);
    }
};

void printList(const list<double> &L)
{

    std::cout << "mylist contains: ";
    for (auto it = L.begin(); it != L.end(); it++)
    {

        cout << *it << " ";
    }

    cout << endl;
}
void test()
{
    double mydoubles[] = {12.15, 2.72, 73.0, 12.77, 3.14,
                          12.77, 73.35, 72.25, 15.3, 72.25};
    std::list<double> mylist(mydoubles, mydoubles + 10);
    printList(mylist);

    mylist.sort(); //  2.72,  3.14, 12.15, 12.77, 12.77,
                   // 15.3,  72.25, 72.25, 73.0,  73.35
    printList(mylist);

    mylist.unique(); //  2.72,  3.14, 12.15, 12.77
                     // 15.3,  72.25, 73.0,  73.35
    printList(mylist);

    mylist.unique(same_integral_part); //  2.72,  3.14, 12.15
                                       // 15.3,  72.25, 73.0
    printList(mylist);

    mylist.unique(is_near()); //  2.72, 12.15, 72.25

    
}

int main()
{
    test();
    return 0;
}